
import React from 'react';
import classNames from 'classnames';
import { JSEncrypt } from 'jsencrypt';
import { getLocalRoutes } from '@/router/config';
import config from '@/config';

import { Form, Input,Button } from 'antd';


import css from './index.module.less';

// 密码加密
const setEncrypt = (publicKey, str) => {
  const jsencrypt = new JSEncrypt();
  jsencrypt.setPublicKey(publicKey);
  return jsencrypt.encrypt(str);
};

const Login = (props) => {
  const formRef = React.useRef();

  const isDisabled = () => {
    return config.isMainApp && !getLocalRoutes().length;
  };

  const [disabled, setDisabled] = React.useState(isDisabled());


  React.useEffect(() => {
    getAllSubAppRoutes();
  }, []);

  const getAllSubAppRoutes = async () => {
    if (!config.isMainApp) return;
  };




  const loginHandle = async () => {
    try {
      const data = await formRef.current.validateFields();
     
    } catch (err) {
      // ...
    }
  };

  return (
    <div className={classNames(css.login_wrapper)}>
      <div className={classNames(css.left)}>
        <div className={classNames(css.logo)}>
          {/* <img src={} height="50" alt="暂无" /> */}
        </div>
      </div>
      <div className={classNames(css.right)}>
        <div className={classNames(css.main)}>
          <h4 className={classNames(css.title)}></h4>
          <div className={classNames(css.container)}>
            <Form
              ref={formRef}
              labelCol={{ span: 0 }}
              wrapperCol={{ span: 24 }}
              className={classNames(css.login_form)}
            >
              <Form.Item name="userName" rules={[{ required: true, message: '请输入用户名' }]}>
                <Input placeholder="请输入用户名" />
              </Form.Item>
              <Form.Item
                name="passWord"
                rules={[{ required: true, message: '请输入密码' }]}
                onKeyUp={(ev) => {
                  if (ev.keyCode === 13 && !disabled) {
                    loginHandle();
                  }
                }}
              >
                <Input.Password placeholder="请输入密码" />
              </Form.Item>
              <div className={css.forget_pwd}>
                <a href="#">忘记密码</a>
              </div>
              <Form.Item>
                <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                  <Button type="primary" htmlType="submit">
                    Submit
                </Button>
              </Form.Item>
                <div className={classNames(css.tooltip)}>
                  建议您在Chrome浏览器(98版本以上)或Edge浏览器使用
                </div>
              </Form.Item>
            </Form>
          </div>
        </div>
      </div>
    </div>
  );
};

export default Login;
